为静态路由指定下一跳 IP 地址

您所在的位置:网站首页 在路由器上配置默认路由的下一跳 192168101 为静态路由指定下一跳 IP 地址

为静态路由指定下一跳 IP 地址

2024-05-21 15:09| 来源: 网络整理| 查看: 265

如果将静态路由指向广播接口,则仅当广播接口处于活动状态时,路由才会被插入到路由表中。当静态路由点的下一跳对接口的,路由器考虑其中每一台在路由内的范围的主机通过该接口时,直接地被连接此配置不是推荐的,因为。此类静态路由的一个示例是 ip route 0.0.0.0 0.0.0.0 Ethernet0。

在此类配置下,路由器在以太网上为路由器在默认路由中找到的每个目的地执行地址解析协议 (ARP),因为路由器将所有这些目的地都视为直接连接到以太网 0。这种静态路由(特别是被许多数据包用于许多不同的目的子网时)可能会导致高处理器利用率和非常大的 ARP 缓存(以及内存分配失败)。因此,不建议使用这种静态路由。

在直连接口上指定下一跳地址时,它会阻止路由器为每个目的地址执行 ARP。例如 ip route 0.0.0.0 0.0.0.0 Ethernet0 192.168.1.1。只能指定直连的下一跳地址,但不建议这样做,原因如本文档所述。不需要指定直连的下一跳地址。可以指定远程下一跳地址以及远程下一跳递归的接口。

如果下一跳的接口关闭,并且下一跳可通过递归路由到达,则应同时指定下一跳 IP 地址和应在其中查找下一跳的备用接口。例如, IP路由0.0.0.0 0.0.0.0序列3/3 192.168.20.1。这使静态路由安装变得更具确定性。

浮动静态路由示例

本示例描述浮动静态路由的使用,并说明使用静态路由命令指定出站接口和下一跳地址的必要性。

问题

在下图中的网络配置中,一个主机 172.31.10.1 连接到互联网。在此示例中,主机连接到远程互联网主机 10.100.1.1:

在图中的网络配置中,一个主机 172.31.10.1 连接到互联网在图中的网络配置中,一个主机 172.31.10.1 连接到互联网

在此配置下,主链路是 R1 上串行端口 1/0 与 R2 上串行端口 1/0 之间的链路,用于从主机 172.31.10.1 向互联网传递流量。主机 10.100.1.1 在这里用作互联网主机的一个例子。R1 上串行端口 2/0 与 R2 上串行端口 2/0 之间的链路是备份链路。只有在主链路出现故障时才使用备份链路。这是使用指向主链路的静态路由和指向备份链路的浮动静态路由来部署的。

在 R1 上有两个静态路由到同一目的地 (172.31.10.0/24)。一个路由是常规静态路由,另一个路由是浮动静态路由,后者是到局域网中目的网络的备份或冗余路径。此情景中的问题是,当主链路关闭时,系统不会在路由表中安装浮动静态路由。

这是 R1 上的配置:

代码语言:javascript复制hostname R1 ! interface Serial1/0 ip address 10.10.10.1 255.255.255.252 ! interface Serial2/0 ip address 10.10.20.1 255.255.255.252 ! ip route 10.0.0.0 255.0.0.0 192.168.10.2 ! This is the primary route to get to hosts on the Internet. ip route 172.31.10.0 255.255.255.0 10.10.10.2 ! This is the preferred route to the LAN. ip route 172.31.10.0 255.255.255.0 10.10.20.2 250 ! This is the floating static route to the LAN.

这是 R2 上的配置:

代码语言:javascript复制hostname R2 ! interface Serial1/0 ip address 10.10.10.2 255.255.255.252 ! interface Serial2/0 ip address 10.10.20.2 255.255.255.252 ! ip route 0.0.0.0 0.0.0.0 10.10.10.1 ip route 0.0.0.0 0.0.0.0 10.10.20.1 250 !

这是 R1 的路由表:

代码语言:javascript复制R1#show ip route Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP        D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area        N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2        E1 - OSPF external type 1, E2 - OSPF external type 2        i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2        ia - IS-IS inter area, * - candidate default, U - per-user static route        o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP        a - application route        + - replicated route, % - next hop override Gateway of last resort is not set      10.0.0.0/8 is variably subnetted, 5 subnets, 3 masks S       10.0.0.0/8 [1/0] via 192.168.10.2 C       10.10.10.0/30 is directly connected, Serial1/0 L       10.10.10.1/32 is directly connected, Serial1/0 C       10.10.20.0/30 is directly connected, Serial2/0 L       10.10.20.1/32 is directly connected, Serial2/0      172.31.0.0/24 is subnetted, 1 subnets S       172.31.10.0 [1/0] via 10.10.10.2      192.168.10.0/24 is variably subnetted, 2 subnets, 2 masks C       192.168.10.0/30 is directly connected, Serial3/0 L       192.168.10.1/32 is directly connected, Serial3/0

当从主机执行到互联网主机 10.100.1.1 的 ping 操作时,它按预期运行:

代码语言:javascript复制host#ping 10.100.1.1 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 10.100.1.1, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 73/78/80 ms

从主机到互联网主机 10.100.1.1 的跟踪路由显示:

代码语言:javascript复制host#traceroute 10.100.1.1 Type escape sequence to abort. Tracing the route to 10.100.1.1 VRF info: (vrf in name/id, vrf out name/id) 1 172.31.10.2 1 msec 1 msec 1 msec 2 10.10.10.1 31 msec 39 msec 39 msec 3 192.168.10.2 80 msec * 80 msec

使用的主链路是 10.10.10.0/30。

如果关闭 R1 上的串行端口 1/0 以测试故障切换,则预计 R1 会将浮动静态路由安装到本地局域网 172.31.10.0,并且 R2 通过 10.10.20.1 将浮动静态路由安装到 0.0.0.0。您应该预期流量流过备份链路。

代码语言:javascript复制R1#conf t Enter configuration commands, one per line. End with CNTL/Z. R1(config)#interface serial1/0 R1(config-if)#shutdown R1(config-if)#end R1#

但是,局域网 172.31.10.0/24 的静态路由仍保留在 R1 的路由表中:

代码语言:javascript复制R1#show ip route Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP        D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area        N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2        E1 - OSPF external type 1, E2 - OSPF external type 2        i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2        ia - IS-IS inter area, * - candidate default, U - per-user static route        o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP        a - application route        + - replicated route, % - next hop override Gateway of last resort is not set      10.0.0.0/8 is variably subnetted, 3 subnets, 3 masks S       10.0.0.0/8 [1/0] via 192.168.10.2 C       10.10.20.0/30 is directly connected, Serial2/0 L       10.10.20.1/32 is directly connected, Serial2/0      172.31.0.0/24 is subnetted, 1 subnets S       172.31.10.0 [1/0] via 10.10.10.2      192.168.10.0/24 is variably subnetted, 2 subnets, 2 masks C       192.168.10.0/30 is directly connected, Serial3/0 L       192.168.10.1/32 is directly connected, Serial3/0代码语言:javascript复制R1#show ip route 172.31.10.0 Routing entry for 172.31.10.0/24 Known via "static", distance 1, metric 0 Routing Descriptor Blocks: * 10.10.10.2      Route metric is 0, traffic share count is 1 R1#show ip route 10.10.10.2 Routing entry for 10.0.0.0/8 Known via "static", distance 1, metric 0 Routing Descriptor Blocks: * 192.168.10.2      Route metric is 0, traffic share count is 1

来自主机的 ping 操作和跟踪路由不再起作用:

代码语言:javascript复制host#ping 10.100.1.1    Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 10.100.1.1, timeout is 2 seconds: ..... Success rate is 0 percent (0/5) host#traceroute 10.100.1.1 Type escape sequence to abort. Tracing the route to 10.100.1.1 VRF info: (vrf in name/id, vrf out name/id) 1 172.31.10.2 1 msec 1 msec 1 msec 2 * * * 3 * * * 4 * * * 5 * * * 6 * * * 7 * * * 8 * * * 9 * * * 10 * * * 11 * * * ?

浮动静态路由没有安装在 R1 上,并且主静态路由仍然位于 R1 的路由表中,即使串行端口 1/0 链路已关闭。发生这种情况的原因是静态路由在本质上是递归的。只要您有一个路由对下一跳,您在路由表总是保留静态路由。

在这个问题情景中,您可能会预期,由于主链路已关闭,因此应该在 R1 的路由表中安装管理距离为 250 的浮动静态路由。但是,由于常规静态路由仍保留在路由表中,所以未在路由表中安装浮动静态路由。下一跳地址 10.10.10.2 成功通过路由表中的静态路由 10.0.0.0/8 递归到 192.168.10.2。

解决方案

在下一跳不能递归到其他静态路由的 R1 上配置静态路由。思科建议您为静态路由同时配置出站接口和下一跳地址。如果是串行接口,指定出站接口就已足够,因为串行接口是点对点接口。如果出站接口是以太网接口,则必须同时配置出站接口和下一跳地址。

以下示例中,为局域网配置静态路由时指定了出站接口:

代码语言:javascript复制R1#conf t Enter configuration commands, one per line. End with CNTL/Z. R1(config)#no ip route 172.31.10.0 255.255.255.0 10.10.10.2 R1(config)#ip route 172.31.10.0 255.255.255.0 Serial1/0 R1(config)#end代码语言:javascript复制R1#show ip route Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP        D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area        N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2        E1 - OSPF external type 1, E2 - OSPF external type 2        i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2        ia - IS-IS inter area, * - candidate default, U - per-user static route        o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP        a - application route        + - replicated route, % - next hop override Gateway of last resort is not set      10.0.0.0/8 is variably subnetted, 3 subnets, 3 masks S       10.0.0.0/8 [1/0] via 192.168.10.2 C       10.10.20.0/30 is directly connected, Serial2/0 L       10.10.20.1/32 is directly connected, Serial2/0      172.31.0.0/24 is subnetted, 1 subnets S       172.31.10.0 [250/0] via 10.10.20.2      192.168.10.0/24 is variably subnetted, 2 subnets, 2 masks C       192.168.10.0/30 is directly connected, Serial3/0 L       192.168.10.1/32 is directly connected, Serial3/0

从主机到互联网主机的 ping 操作和跟踪路由现在正常运行,并使用备份链路:

代码语言:javascript复制R1#show ip route 172.31.10.0 Routing entry for 172.31.10.0/24 Known via "static", distance 250, metric 0 (connected) Routing Descriptor Blocks: * 10.10.20.2      Route metric is 0, traffic share count is 1代码语言:javascript复制host#ping 10.100.1.1 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 10.100.1.1, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 76/79/80 ms host#traceroute 10.100.1.1 Type escape sequence to abort. Tracing the route to 10.100.1.1 VRF info: (vrf in name/id, vrf out name/id) 1 172.31.10.2 1 msec 1 msec 1 msec 2 10.10.20.1 38 msec 39 msec 40 msec 3 192.168.10.2 80 msec * 80 msec结论

强烈建议您在配置静态路由时指定出站接口和下一跳 IP 地址。如果出站接口是点对点类型的链路(例如,串行链路),则不需要指定下一跳地址。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3